<template>
  <div><back></back></div>
  <div class="box">
    <h2>修改密码</h2>
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="username"
          name="username"
          label="用&emsp;户&emsp;名"
          placeholder="请填写你的手机号"
          colon
          :rules="[{ required: true, message: '请填写你的手机号', pattern }]"
        />
        <van-field
          v-model="oldpassword"
          type="password"
          name="oldpassword"
          label="原&nbsp;始&nbsp;密&nbsp;码"
          placeholder="请填写你的原始密码"
          colon
          :rules="[{ required: true, message: '请填写原始密码' }]"
        />
        <van-field
          v-model="newpassword1"
          type="password"
          name="newpassword1"
          label="新&emsp;密&emsp;码"
          placeholder="请填写新密码"
          colon
          :rules="[{ required: true, message: '请填写新密码' }]"
        />
        <van-field
          v-model="newpassword2"
          type="password"
          name="newpassword2"
          label="确&nbsp;认&nbsp;密&nbsp;码"
          placeholder="请再次填写新密码"
          colon
          :rules="[{ required: true, message: '请再次填写新密码' }]"
        />
      </van-cell-group>
      <div style="margin: 16px">
        <van-button round block type="primary" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script setup>
import { showSuccessToast, showFailToast } from "vant";

import { ref } from "vue";
// 返回按钮
import back from "@/components/Back.vue";

const username = ref("");
const oldpassword = ref("");
const newpassword1 = ref("");
const newpassword2 = ref("");

// 手机号的验证
const pattern = /\d{11}/;

function onSubmit(values) {
  if (values.newpassword1 === values.newpassword2) {
    showSuccessToast("密码修改成功");
    username.value = "";
    oldpassword.value = "";
    newpassword1.value = "";
    newpassword2.value = "";
  } else {
    showFailToast("密码不一致");
    newpassword2.value = "";
  }
}
</script>

<style lang="less" scoped>
.box {
  h2 {
    line-height: 1;

    font-weight: 600;
    margin-bottom: 7.133vw;
    margin-left: 5.067vw;
  }
  :deep(.van-button--round) {
    background-color: rgb(255, 60, 80);
    border-radius: 2vw;
    border: none;
    margin-top: 74vw;
  }
}
</style>
